package com.daohang361.imqq.pugin.service;

import org.apache.mina.core.session.IoSession;

import com.daohang361.imqq.Asycore.Connector;
import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.ServerContex.SessionContex;
import com.daohang361.imqq.encoder.InterfaceEncoder;
import com.daohang361.imqq.hotLoader.PuginManager;
import com.daohang361.imqq.service.InterfaceService;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-5-13 下午07:09:22 
 */
public class SendMessageToFriend implements InterfaceService{

	@Override
	public Object doService(Object... o) {
		QQUser myqq = SessionContex.getQQUser(Integer.parseInt( o[0]+""));
		byte[] sendFriendKey=SessionContex.getSendFriendKey( o[0]+""+o[1]+"");
		InterfaceEncoder encoder = ((InterfaceEncoder) PuginManager.GetPuginByKey("EncoderCD"));
		
		Connector connector =SessionContex.getConnector(Integer.parseInt( o[0]+""));
		IoSession session=connector.getSession();
		if(sendFriendKey==null)
		{
			byte[] temp=encoder.encode(myqq, 0xcd,o);
			myqq.setCommand(0xcd);
			myqq.addDirectSendByte(temp);
			session.write(myqq);
			//sendFriendKey=SessionContex.getSendFriendKey( o[0]+""+o[1]+"");
		}

		byte[] temp=encoder.encode(myqq, 0xcd,o);
		myqq.setCommand(0xcd);
		myqq.addDirectSendByte(temp);
		session.write(myqq);
		
		new GetFriendHead().doService(o);
		return null;
	}

	@Override
	public Object invoke(Object... o) {
		return null;
	}

}
